rm(list = setdiff(ls(), lsf.str()))


#Turnout: Germany: Vote-------------------------
load("Study 1/Altered Data/Study1_Germany.RData")
summary(germany<-glm(didnotvote~zero1(agre)+zero1(open)+zero1(con)+zero1(ext)+zero1(neu)+female+age + income+income_missing + education + zero1(econ_cons)+zero1(social_cons), data=data, family=binomial,  weights = z000011a))
germany_vote<-data.frame(exp(cbind(coef(germany), confint(germany)))) 
germany_vote<-germany_vote[2,]                
colnames(germany_vote )[1]="Estimate"
colnames(germany_vote )[2]="Lo"
colnames(germany_vote )[3]="Up"
germany_vote$sample<-"GESIS 2017"
germany_vote$Country<-"Germany"

#Turnout: US ANES 2016: Vote----------------------
load("Study 1/Altered Data/Study 1_US_ANES2016.Rdata")

Trump_vote <- glm(didnotvote ~ zero1(agreeableness) + zero1(openness) + zero1(conscientiousness) + zero1(extraversion) + zero1(neuroticism) + zero1(authoritarianism) +  female + age +  black + Indian + Asian + Hawaiian + Other + as.factor(education) + income + income_missing + zero1(post_lib_cons_placement), data=data, family="binomial")
us_trump<-data.frame(exp(cbind(coef(Trump_vote), confint(Trump_vote)))) 
us_trump<-us_trump[2,]                
colnames(us_trump )[1]="Estimate"
colnames(us_trump )[2]="Lo"
colnames(us_trump )[3]="Up"
us_trump$sample<-"ANES 2016"
us_trump$Country<-"United\n States"

#Turnout: Denmark: Vote-----------------
load("Study 1/Altered Data/Study1_Denmark.RData")
m10<-glm(didnotvote~zero1(agre)+zero1(open)+zero1(con)+zero1(ext)+zero1(neu)+female+age+as.factor(v2010_education)+income + income_missing + zero1(econ_cons) + zero1(social) + zero1(cynicism), data=data, family="binomial")
DK_10<-data.frame(exp(cbind(coef(m10), confint(m10)))) 
DK_10<-DK_10[2,]                
colnames(DK_10 )[1]="Estimate"
colnames(DK_10 )[2]="Lo"
colnames(DK_10 )[3]="Up"
DK_10$sample<-"2011"
DK_10$Country<-"Denmark"

#Turnout: Netherlands Election 2017 -------------
load("Study 1/Altered Data/Study1_NL_17.RData")
m1<-glm(didnotvote ~ zero1(agre) + zero1(open) + zero1(con) + zero1(ext) + zero1(neu) + female + age+ as.factor(education) + income + income_missing  + zero1(econ_cons) + zero1(anti_immi) + zero1(cynicism) , data=data, family="binomial")
NL_17<-data.frame(exp(cbind(coef(m1), confint(m1)))) 
NL_17<-NL_17[2,]                
colnames(NL_17 )[1]="Estimate"
colnames(NL_17 )[2]="Lo"
colnames(NL_17 )[3]="Up"
NL_17$sample<-"Election 2017"
NL_17$Country<-"Netherlands"

#Turnout: Netherlands Election 2012 -------------
load("Study 1/Altered Data/Study1_NL_12.RData")
m2<-glm(didnotvote ~ zero1(agre) + zero1(open) + zero1(con) + zero1(ext) + zero1(neu) + female + age + as.factor(education) +income + income_missing + zero1(econ_cons11) + zero1(anti_immi11) + zero1(cynicism11), data=data, family="binomial")
NL_12<-data.frame(exp(cbind(coef(m2), confint(m2)))) 
NL_12<-NL_12[2,]                
colnames(NL_12 )[1]="Estimate"
colnames(NL_12 )[2]="Lo"
colnames(NL_12 )[3]="Up"
NL_12$sample<-"Election 2012"
NL_12$Country<-"Netherlands"

#Turnout: Spain --------------------
load("Study 1/Altered Data/Study1_Spain.Rdata")
Podemos_full <-  miceadds::glm.cluster(turnout ~zero1(A_critical) + zero1(open) +zero1(con)+ zero1(ext) +zero1(neu) +female +age + income + income_missing + as.factor(education) + zero1(lr_placement) + zero1(cynicism), data=data, family=binomial, cluster="CCAA")

spain<-data.frame(exp(cbind(coef(Podemos_full), confint(Podemos_full)))) 
spain<-spain[2,]                
colnames(spain )[1]="Estimate"
colnames(spain )[2]="Lo"
colnames(spain )[3]="Up"
spain$sample<-"2016"
spain$Country<-"Spain"

#Turnout: Switzerland Elections 2015 ----------------------------
load("Study 1/Altered Data/Study1_Swiss_Elections15.RData")
swissElections15 <- glm(didnotvote ~ zero1(agre) + zero1(open) + zero1(con) + ext + neu + female + age + as.factor(W3_spr) + as.factor(education) + income + income_missing + zero1(econ_socialspending) + zero1(social_limit_immi), data=data, family="binomial")
swissElections15<-data.frame(exp(cbind(coef(swissElections15), confint(swissElections15)))) 
swissElections15<-swissElections15[2,]                
colnames(swissElections15 )[1]="Estimate"
colnames(swissElections15 )[2]="Lo"
colnames(swissElections15 )[3]="Up"
swissElections15$sample<-"Election 2015"
swissElections15$Country<-"Switzerland"


#Turnout: UK - British Election Studies -----------------------
load("Study 1/Altered Data/Study1_UK_BES.RData")
vote.UKIPw6 <- glm(didnotvote ~zero1(agre) + zero1(open) + zero1(con) + zero1(ext) + zero1(neu) +female +Age+ Age_missing + Ed_GSCE_DG + Ed_GSCE_AC + Ed_A_level + Ed_Undergraduate + Ed_Postgrad + income + income_missing + zero1(w6_pol_cynicism) + zero1(w4_immiatt) + zero1(w6_redistribution), data=data_BES, family="binomial")

UK_bes<-data.frame(exp(cbind(coef(vote.UKIPw6), confint(vote.UKIPw6)))) 
UK_bes_agre<-UK_bes[2,]                
colnames(UK_bes_agre )[1]="Estimate"
colnames(UK_bes_agre )[2]="Lo"
colnames(UK_bes_agre )[3]="Up"
UK_bes_agre$sample<-"UK Election 2015"
UK_bes_agre$Country<-"United \n Kingdom"

#Turnout: Venezuela -----------------
load("Study 1/Altered Data/Study1_Venezuela07.RData")
venezuela <-glm(didnotvote ~ zero1(agre) + zero1(open)+ zero1(con) +zero1(ext)+ zero1(neu)+ female+ age+ income+ income_missing+ education_years+ lr_placement + lr_placement_missing, data=data, family="binomial")
cl.cov_base <- cluster.vcov(venezuela, data$venentidad) # cluster-robust SEs for ols1
cl.robust.se.base <- sqrt(diag(cl.cov_base))

venezuela_data<-data.frame(exp(cbind(coef(venezuela), confint(venezuela)))) 
venezuela_data<-venezuela_data[2,]                
colnames(venezuela_data )[1]="Estimate"
colnames(venezuela_data )[2]="Lo"
colnames(venezuela_data )[3]="Up"
venezuela_data$sample<-"2007"
venezuela_data$Country<-"Venezuela"

#Turnout: Create plot -------------
comb_vote<-rbind(UK_bes_agre, swissElections15, NL_12, NL_17, spain, DK_10, us_trump, germany_vote, venezuela_data)
comb_vote$sample <-factor(comb_vote$sample, levels=c('UK Election 2015', 'Election 2015',  'Election 2017', 'Election 2012','2016', '2011', 'ANES 2016', 'GESIS 2017', '2007'))
comb_vote$Country <-factor(comb_vote$Country, levels=c('United \n Kingdom', 'Germany', 'Denmark', 'Netherlands',  'Switzerland', 'Spain', 'Venezuela', 'United\n States'))

#Turnout: Plot figure------------
fig2_vote <- ggplot(comb_vote ,aes(x=sample, y=Estimate, group=Country))+geom_pointrange(aes(ymin=Lo,ymax=Up), size=1)  + theme_bw()+theme(legend.position="off")+ylab("Odds ratio of abstention (1) versus voting (0)")+xlab("")+geom_hline(yintercept=1,linetype = "dashed", color="red") + coord_flip() + facet_grid(Country~., scales = "free_y")+ theme(axis.text.x=element_text(size=14), strip.text.y=element_text(size=14)) + geom_rect(data = subset(comb_vote,Country == 'Meta \n analysis'),aes(fill = Country),xmin = -Inf,xmax = Inf, ymin = -Inf,ymax = Inf, alpha = 0.3) +  theme(strip.text.y = element_text(angle = 360))

ggsave(fig2_vote, file="Figures/fig2_vote.pdf", dpi=900, width = 8, height =4)



#3 groups: Germany------------------
load("Study 1/Altered Data/Study1_Germany.RData")
vote_multinom<-multinom(populist_other_not~zero1(agre)+zero1(open)+zero1(con)+zero1(ext)+zero1(neu)+female+age + income+income_missing + education + econ_cons+social_cons, data=data,  weights = z000011a)

#calculate odds ratio and confidence intervals
mlogit.odds<-exp(coef(vote_multinom))
mlogit.conf<-as.data.frame(exp(confint(vote_multinom)))

#Vote
germany_other<-cbind(mlogit.odds[1,2], mlogit.conf[2,1:2])
colnames(germany_other)<- c("odds","low","high")
germany_other$party<-"Populist"
germany_other$country<-"Germany"
germany_other$sample<-"GESIS 2017"

#Abstention
germany_abstention<-cbind(mlogit.odds[2,2], mlogit.conf[2,3:4])
colnames(germany_abstention)<- c("odds","low","high")
germany_abstention$party<-"Abstention"
germany_abstention$country<-"Germany"
germany_abstention$sample<-"GESIS 2017"

#3 Groups: US----------------------
load("Study 1/Altered Data/Study 1_US_ANES2016.Rdata")
vote_multinom<-multinom(populist_other_not ~ zero1(agreeableness) + zero1(openness) + zero1(conscientiousness) + zero1(extraversion) + zero1(neuroticism) + zero1(authoritarianism) +  female + age +  black + Indian + Asian + Hawaiian + Other + as.factor(education) + income + income_missing + zero1(post_lib_cons_placement), data=data)

#calculate odds ratio and confidence intervals
mlogit.odds<-exp(coef(vote_multinom))
mlogit.conf<-as.data.frame(exp(confint(vote_multinom)))

#Vote
us_other<-cbind(mlogit.odds[1,2], mlogit.conf[2,1:2])
colnames(us_other)<- c("odds","low","high")
us_other$party<-"Populist"
us_other$country<-"United\n States"
us_other$sample<-"ANES 2016"

#Abstention
us_abstention<-cbind(mlogit.odds[2,2], mlogit.conf[2,3:4])
colnames(us_abstention)<- c("odds","low","high")
us_abstention$party<-"Abstention"
us_abstention$country<-"United\n States"
us_abstention$sample<-"ANES 2016"

#3 Groups: Denmark----------------------
load("Study 1/Altered Data/Study1_Denmark.RData")
vote_multinom <- multinom(populist_other_not ~ zero1(agre)+zero1(open)+zero1(con)+zero1(ext)+zero1(neu)+female+age+as.factor(v2010_education)+income + income_missing + zero1(econ_cons) + zero1(social) + zero1(cynicism), data=data)

#calculate odds ratio and confidence intervals
mlogit.odds<-exp(coef(vote_multinom))
mlogit.conf<-as.data.frame(exp(confint(vote_multinom)))

#Vote
dk_other<-cbind(mlogit.odds[1,2], mlogit.conf[2,1:2])
colnames(dk_other)<- c("odds","low","high")
dk_other$party<-"Populist"
dk_other$country<-"Denmark"
dk_other$sample<-"2011"

#Abstention
dk_abstention<-cbind(mlogit.odds[2,2], mlogit.conf[2,3:4])
colnames(dk_abstention)<- c("odds","low","high")
dk_abstention$party<-"Abstention"
dk_abstention$country<-"Denmark"
dk_abstention$sample<-"2011"

#3 Groups: Netherlands 2012-----------------
load("Study 1/Altered Data/Study1_NL_12.RData")
vote_multinom <- multinom(populist_other_not ~  zero1(agre) + zero1(open) + zero1(con) + zero1(ext) + zero1(neu) + female + age + as.factor(education) +income + income_missing + zero1(econ_cons11) + zero1(anti_immi11) + zero1(cynicism11), data=data)

#calculate odds ratio and confidence intervals
mlogit.odds<-exp(coef(vote_multinom))
mlogit.conf<-as.data.frame(exp(confint(vote_multinom)))

#Vote
nl12_other<-cbind(mlogit.odds[1,2], mlogit.conf[2,1:2])
colnames(nl12_other)<- c("odds","low","high")
nl12_other$party<-"Populist"
nl12_other$country<-"Netherlands"
nl12_other$sample<-"Election 2012"

#Abstention
nl12_abstention<-cbind(mlogit.odds[2,2], mlogit.conf[2,3:4])
colnames(nl12_abstention)<- c("odds","low","high")
nl12_abstention$party<-"Abstention"
nl12_abstention$country<-"Netherlands"
nl12_abstention$sample<-"Election 2012"

#3 Groups: Netherlands 2017-----------------
load("Study 1/Altered Data/Study1_NL_17.RData")
vote_multinom<-multinom(populist_other_not ~ zero1(agre) + zero1(open) + zero1(con) + zero1(ext) + zero1(neu) + female + age+ as.factor(education) + income + income_missing  + zero1(econ_cons) + zero1(anti_immi) + zero1(cynicism) , data=data)

#calculate odds ratio and confidence intervals
mlogit.odds<-exp(coef(vote_multinom))
mlogit.conf<-as.data.frame(exp(confint(vote_multinom)))

#Vote
nl17_other<-cbind(mlogit.odds[1,2], mlogit.conf[2,1:2])
colnames(nl17_other)<- c("odds","low","high")
nl17_other$party<-"Populist"
nl17_other$country<-"Netherlands"
nl17_other$sample<-"Election 2017"

#Abstention
nl17_abstention<-cbind(mlogit.odds[2,2], mlogit.conf[2,3:4])
colnames(nl17_abstention)<- c("odds","low","high")
nl17_abstention$party<-"Abstention" 
nl17_abstention$country<-"Netherlands"
nl17_abstention$sample<-"Election 2017"

#3 Groups: Spain---------------------
load("Study 1/Altered Data/Study1_Spain.Rdata")
vote_multinom<-multinom(populist_other_not ~zero1(A_critical) + zero1(open) +zero1(con)+ zero1(ext) +zero1(neu) +female +age + income + income_missing + as.factor(education) + zero1(lr_placement) + zero1(cynicism), data=data, cluster="CCAA")
mlogit.odds<-exp(coef(vote_multinom))
mlogit.conf<-as.data.frame(exp(confint(vote_multinom)))

#Vote
spain_other<-cbind(mlogit.odds[1,2], mlogit.conf[2,1:2])
colnames(spain_other)<- c("odds","low","high")
spain_other$party<-"Populist"
spain_other$country<-"Spain"
spain_other$sample<-"2016"

#Abstention
spain_abstention<-cbind(mlogit.odds[2,2], mlogit.conf[2,3:4])
colnames(spain_abstention)<- c("odds","low","high")
spain_abstention$party<-"Abstention" 
spain_abstention$country<-"Spain"
spain_abstention$sample<-"2016"

#3 Groups: Switzerland Election 2015-----------------
load("Study 1/Altered Data/Study1_Swiss_Elections15.RData")
vote_multinom <- multinom(populist_other_not ~ zero1(agre) + zero1(open) + zero1(con) + ext + neu + female + age + as.factor(W3_spr) + as.factor(education) + income + income_missing + zero1(econ_socialspending) + zero1(social_limit_immi), data=data)

#calculate odds ratio and confidence intervals
mlogit.odds<-exp(coef(vote_multinom))
mlogit.conf<-as.data.frame(exp(confint(vote_multinom)))

#Vote
swiss_other<-cbind(mlogit.odds[1,2], mlogit.conf[2,1:2])
colnames(swiss_other)<- c("odds","low","high")
swiss_other$party<-"Populist"
swiss_other$country<-"Switzerland"
swiss_other$sample<-"Election 2015"

#Abstention
swiss_abstention<-cbind(mlogit.odds[2,2], mlogit.conf[2,3:4])
colnames(swiss_abstention)<- c("odds","low","high")
swiss_abstention$party<-"Abstention"
swiss_abstention$country<-"Switzerland"
swiss_abstention$sample<-"Election 2015"

#3 Groups: British Election Studies--------------
load("Study 1/Altered Data/Study1_UK_BES.RData")
vote_multinom <- multinom(populist_other_not ~zero1(agre) + zero1(open) + zero1(con) + zero1(ext) + zero1(neu) +female +Age+ Age_missing + Ed_GSCE_DG + Ed_GSCE_AC + Ed_A_level + Ed_Undergraduate + Ed_Postgrad + income + income_missing + zero1(w6_pol_cynicism) + zero1(w4_immiatt) + zero1(w6_redistribution), data=data_BES)

#calculate odds ratio and confidence intervals
mlogit.odds<-exp(coef(vote_multinom))
mlogit.conf<-as.data.frame(exp(confint(vote_multinom)))

#Vote
uk_other<-cbind(mlogit.odds[1,2], mlogit.conf[2,1:2])
colnames(uk_other)<- c("odds","low","high")
uk_other$party<-"Populist"
uk_other$country<-"United Kingdom"
uk_other$sample<-"UK Election 2015"

#Abstention
uk_abstention<-cbind(mlogit.odds[2,2], mlogit.conf[2,3:4])
colnames(uk_abstention)<- c("odds","low","high")
uk_abstention$party<-"Abstention"
uk_abstention$country<-"United Kingdom"
uk_abstention$sample<-"UK Election 2015"


#3 Groups: Venezuela ---------------
load("Study 1/Altered Data/Study1_Venezuela07.RData")
vote_multinom <- multinom(populist_other_not ~ zero1(agre) + zero1(open)+ zero1(con) +zero1(ext)+ zero1(neu)+ female+ age+ income+ income_missing+ education_years+ lr_placement + lr_placement_missing, data=data, cluster=venentidad)
#calculate odds ratio and confidence intervals
mlogit.odds<-exp(coef(vote_multinom))
mlogit.conf<-as.data.frame(exp(confint(vote_multinom)))

#Vote
venez_other<-cbind(mlogit.odds[1,2], mlogit.conf[2,1:2])
colnames(venez_other)<- c("odds","low","high")
venez_other$party<-"Populist"
venez_other$country<-"Venezuela"
venez_other$sample<-"2007"

#Abstention
venez_abstention<-cbind(mlogit.odds[2,2], mlogit.conf[2,3:4])
colnames(venez_abstention)<- c("odds","low","high")
venez_abstention$party<-"Abstention"
venez_abstention$country<-"Venezuela"
venez_abstention$sample<-"2007"


                         


#Pool 3 groups: British Electoin Studies ----------------
load("Study 1/Altered Data/Study1_UK_BES.RData")
data_BES$id <- sample(21811, size = nrow(data_BES))
data_BES$id <- 300000+data_BES$id 
data_BES$education<-ifelse(data_BES$Ed_GSCE_DG==1,1,0)
data_BES$education[data_BES$Ed_GSCE_AC==1]=2
data_BES$education[data_BES$Ed_A_level==1]=3
data_BES$education[data_BES$Ed_Undergraduate==1]=4
data_BES$education[data_BES$Ed_Postgrad==1]=5

data_BES <- data_BES[,which(colnames(data_BES)%in%c("id", "populist_other_not", "agre", "open", "con","ext","neu","female", "Age", "education", "income", "income_missing", "w6_pol_cynicism", "w4_immiatt", "w6_redistribution"))]
data_BES$study <- 2
colnames(data_BES)[colnames(data_BES)=="w6_UKIP_gov_opposition"] <- "populist_multinom"
colnames(data_BES)[colnames(data_BES)=="sex"] <- "female"
colnames(data_BES)[colnames(data_BES)=="Age"] <- "age"
colnames(data_BES)[colnames(data_BES)=="w6_pol_cynicism"] <- "cynicism"
colnames(data_BES)[colnames(data_BES)=="w4_immiatt"] <- "social_cons"
colnames(data_BES)[colnames(data_BES)=="w6_redistribution"] <- "econ_cons"
data_BES$education<-zero1(data_BES$education)
data_BES$econ_cons_missing<-0
data_BES$social_cons_missing<-0
data_BES$cynicism_missing<-0
data_BES$lr_placement<-2
data_BES$lr_placement_missing<-1

data_BES$agre<-zero1(data_BES$agre)
data_BES$open<-zero1(data_BES$open)
data_BES$con<-zero1(data_BES$con)
data_BES$ext<-zero1(data_BES$ext)
data_BES$neu<-zero1(data_BES$neu)
data_BES$cynicism<-zero1(data_BES$cynicism)
data_BES$social_cons<-zero1(data_BES$social_cons)
data_BES$econ_cons<-zero1(data_BES$econ_cons)


#Pool 3 groups: Germany----------------
load("Study 1/Altered Data/Study1_Germany.RData")
data_germany <- data[,which(colnames(data)%in%c("z000001a", "populist_other_not", "agre", "open", "con", "ext","neu", "female", "age", "education", "income", "income_missing", "econ_cons", "social_cons"))]
colnames(data_germany)[colnames(data_germany)=="z000001a"] <- "id"
data_germany$open<- zero1(data_germany$open)
data_germany$con<- zero1(data_germany$con)
data_germany$ext<- zero1(data_germany$ext)
data_germany$agre<- zero1(data_germany$agre)
data_germany$neu<- zero1(data_germany$neu)
data_germany$social_cons<- zero1(data_germany$social_cons)

data_germany$econ_cons_missing<-0
data_germany$social_cons_missing<-0
data_germany$cynicism<-0
data_germany$cynicism_missing<-1
data_germany$lr_placement<-2
data_germany$lr_placement_missing<-1
data_germany$study<-3


#Pool 3 groups: Denmark----------------
load("Study 1/Altered Data/Study1_Denmark.RData")
data_DK <- data[,which(colnames(data)%in%c("populist_other_not", "agre", "open", "con","ext","neu","female", "age", "income", "income_missing", "v2010_education", "social", "econ_cons", "cynicism"))]
data_DK$study <- 4

data_DK$id <- sample(4090, size = nrow(data_DK))
data_DK$id <- 900000+data_DK$id 
colnames(data_DK)[colnames(data_DK)=="v2010_education"] <- "education"
colnames(data_DK)[colnames(data_DK)=="social"] <- "social_cons"

data_DK$open<- zero1(data_DK$open)
data_DK$con<- zero1(data_DK$con)
data_DK$ext<- zero1(data_DK$ext)
data_DK$agre<- zero1(data_DK$agre)
data_DK$neu<- zero1(data_DK$neu)
data_DK$education<- zero1(data_DK$education)
data_DK$econ_cons<- zero1(data_DK$econ_cons)
data_DK$cynicism<- zero1(data_DK$cynicism)
data_DK$social_cons<- zero1(data_DK$social_cons)
data_DK$econ_cons_missing<-0
data_DK$social_cons_missing<-0
data_DK$cynicism_missing<-0
data_DK$lr_placement<-2
data_DK$lr_placement_missing<-1

#Pool 3 groups: Netherlands 2012----------------
load("Study 1/Altered Data/Study1_NL_12.RData")
data_NL12 <- data[,which(colnames(data)%in%c("nomem_encr", "populist_other_not", "agre", "open", "con","ext","neu","female", "age", "income", "income_missing", "education", "cynicism11", "anti_immi11", "econ_cons11"))]
data_NL12$study <- 6
colnames(data_NL12)[colnames(data_NL12)=="nomem_encr"] <- "id"
colnames(data_NL12)[colnames(data_NL12)=="econ_cons11"] <- "econ_cons"
colnames(data_NL12)[colnames(data_NL12)=="anti_immi11"] <- "social_cons"
colnames(data_NL12)[colnames(data_NL12)=="cynicism11"] <- "cynicism"
data_NL12$econ_cons<- zero1(data_NL12$econ_cons)
data_NL12$social_cons<- zero1(data_NL12$social_cons)
data_NL12$cynicism<- zero1(data_NL12$cynicism)
data_NL12$education<- zero1(data_NL12$education)
data_NL12$open<- zero1(data_NL12$open)
data_NL12$con<- zero1(data_NL12$con)
data_NL12$ext<- zero1(data_NL12$ext)
data_NL12$agre<- zero1(data_NL12$agre)
data_NL12$neu<- zero1(data_NL12$neu)
data_NL12$econ_cons_missing<-0
data_NL12$social_cons_missing<-0
data_NL12$cynicism_missing<-0
data_NL12$lr_placement<-2
data_NL12$lr_placement_missing<-1


#Pool 3 groups: Netherlands 2017----------------
load("Study 1/Altered Data/Study1_NL_17.RData")
data_NL17 <- data[,which(colnames(data)%in%c("nomem_encr", "populist_other_not", "agre", "open", "con","ext","neu","female", "age", "income", "income_missing", "education", "anti_immi", "econ_cons", "cynicism"))]

data_NL17$study <- 9
data_NL17$education<-zero1(data_NL17$education)
data_NL17$open<- zero1(data_NL17$open)
data_NL17$con<- zero1(data_NL17$con)
data_NL17$ext<- zero1(data_NL17$ext)
data_NL17$agre<- zero1(data_NL17$agre)
data_NL17$neu<- zero1(data_NL17$neu)
colnames(data_NL17)[colnames(data_NL17)=="nomem_encr"] <- "id"
colnames(data_NL17)[colnames(data_NL17)=="econ_cons"] <- "econ_cons"
colnames(data_NL17)[colnames(data_NL17)=="anti_immi"] <- "social_cons"
colnames(data_NL17)[colnames(data_NL17)=="cynicism"] <- "cynicism"
data_NL17$econ_cons<- zero1(data_NL17$econ_cons)
data_NL17$social_cons<- zero1(data_NL17$social_cons)
data_NL17$cynicism<- zero1(data_NL17$cynicism)

data_NL17$econ_cons_missing<-0
data_NL17$social_cons_missing<-0
data_NL17$cynicism_missing<-0
data_NL17$lr_placement<-2
data_NL17$lr_placement_missing<-1

#Pool 3 groups: Spain----------------
load("Study 1/Altered Data/Study1_Spain.Rdata")
data$lr_placement<-zero1(data$lr_placement)
data$lr_placement[is.na(data$lr_placement)]=2
data$lr_placement_missing<-ifelse(data$lr_placement==2,1,0)
data$agre <- zero1(data$A_critical)
data$id <- sample(6175, size = nrow(data))
data$id <- 700000+data$id 

data_spain <- data[,which(colnames(data)%in%c("id", "populist_other_not", "agre", "open", "con","ext","neu","female", "age", "education", "lr_placement_missing", "lr_placement", "cynicism", "income", "income_missing"))]
data_spain$study <- 13

data_spain$open<-zero1(data_spain$open)
data_spain$con<-zero1(data_spain$con)
data_spain$ext<-zero1(data_spain$ext)
data_spain$neu<-zero1(data_spain$neu)
data_spain$cynicism<-zero1(data_spain$cynicism)
data_spain$education<-zero1(data_spain$education)

data_spain$econ_cons_missing<-1
data_spain$social_cons_missing<-1
data_spain$cynicism_missing<-0
data_spain$econ_cons<-2
data_spain$social_cons<-2

#Pool 3 groups: Switzerland----------------
load("Study 1/Altered Data/Study1_Swiss_Elections15.RData")
swiss_election <- data[,which(colnames(data)%in%c("populist_other_not", "agre", "open", "con","ext","neu","female", "age", "education", "income_missing", "income", "econ_socialspending", "social_limit_immi"))]

swiss_election$study <- 12
swiss_election$id <- sample(11073, size = nrow(swiss_election))
swiss_election$id <- 1000000+swiss_election$id
colnames(swiss_election)[colnames(swiss_election)=="social_limit_immi"] <- "social_cons"
colnames(swiss_election)[colnames(swiss_election)=="econ_socialspending"] <- "econ_cons"

swiss_election$open<- zero1(swiss_election$open)
swiss_election$con<- zero1(swiss_election$con)
swiss_election$ext<- zero1(swiss_election$ext)
swiss_election$agre<- zero1(swiss_election$agre)
swiss_election$neu<- zero1(swiss_election$neu)

swiss_election$education <- zero1(swiss_election$education)
swiss_election$social_cons <- zero1(swiss_election$social_cons)
swiss_election$econ_cons <- zero1(swiss_election$econ_cons)

swiss_election$econ_cons_missing<-0
swiss_election$social_cons_missing<-0
swiss_election$cynicism_missing<-1
swiss_election$cynicism<-2
swiss_election$econ_cons_missing<-0
swiss_election$social_cons_missing<-0
swiss_election$lr_placement<-2
swiss_election$lr_placement_missing<-1




#Pool 3 groups: US----------------
load("Study 1/Altered Data/Study 1_US_ANES2016.Rdata")
data_anes <- data[,which(colnames(data)%in%c("populist_other_not", "agreeableness", "openness", "conscientiousness","extraversion","neuroticism","female", "age", "education", "income", "income_missing", "post_lib_cons_placement"))]
data_anes$id <- sample(4271, size = nrow(data_anes))
data_anes$id <- 1100000+data_anes$id 

colnames(data_anes)[colnames(data_anes)=="agreeableness"] <- "agre"
colnames(data_anes)[colnames(data_anes)=="openness"] <- "open"
colnames(data_anes)[colnames(data_anes)=="conscientiousness"] <- "con"
colnames(data_anes)[colnames(data_anes)=="extraversion"] <- "ext"
colnames(data_anes)[colnames(data_anes)=="neuroticism"] <- "neu"
colnames(data_anes)[colnames(data_anes)=="post_lib_cons_placement"] <- "lr_placement"

data_anes$education<- zero1(data_anes$education)
data_anes$lr_placement<- zero1(data_anes$lr_placement)

data_anes$open<- zero1(data_anes$open)
data_anes$con<- zero1(data_anes$con)
data_anes$ext<- zero1(data_anes$ext)
data_anes$agre<- zero1(data_anes$agre)
data_anes$neu<- zero1(data_anes$neu)

data_anes$econ_cons<-0
data_anes$econ_cons_missing<-1
data_anes$social_cons<-0
data_anes$social_cons_missing<-1
data_anes$cynicism<-0
data_anes$cynicism_missing<-1
data_anes$lr_placement_missing<-0
data_anes$study<-15




#Pool 3 groups: Venezuela-------------

load("Study 1/Altered Data/Study1_Venezuela07.RData")
data$id <- sample(1510, size = nrow(data))
data$id <- 600000+data$id 

data_venezuela <- data[,which(colnames(data)%in%c("id", "populist_other_not", "agre", "open", "con","ext","neu","female", "age", "income", "income_missing", "education_years", "lr_placement"))]
colnames(data_venezuela)[colnames(data_venezuela)=="education_years"] <- "education"

data_venezuela$study <- 14
data_venezuela$open<- zero1(data_venezuela$open)
data_venezuela$con<- zero1(data_venezuela$con)
data_venezuela$ext<- zero1(data_venezuela$ext)
data_venezuela$agre<- zero1(data_venezuela$agre)
data_venezuela$neu<- zero1(data_venezuela$neu)
data_venezuela$education<- zero1(data_venezuela$education)
data_venezuela$lr_placement<- zero1(data_venezuela$lr_placement)

data_venezuela$econ_cons_missing<-1
data_venezuela$social_cons_missing<-1
data_venezuela$cynicism_missing<-1
data_venezuela$econ_cons<-2
data_venezuela$social_cons<-2
data_venezuela$cynicism<-2
data_venezuela$lr_placement_missing<-2

#Pool 3 groups: merge & run model----------

data_meta <- rbind(data_BES,  data_germany, data_DK, data_NL12, data_NL17, data_spain, swiss_election, data_anes, data_venezuela)

data_meta<-na.omit(data_meta)
vote_multinom <- multinom(populist_other_not ~ agre + open + con + ext + neu +age + female + education + income + income_missing + social_cons  + econ_cons+ cynicism  + lr_placement + as.factor(study) , data=data_meta)

#calculate odds ratio and confidence intervals
mlogit.odds<-exp(coef(vote_multinom))
mlogit.conf<-as.data.frame(exp(confint(vote_multinom)))

#Vote
meta_other<-cbind(mlogit.odds[1,2], mlogit.conf[2,1:2])
colnames(meta_other)<- c("odds","low","high")
meta_other$party<-"Populist"
meta_other$country<-"Pooled\n analysis"
meta_other$sample<-"Pooled"

#Abstention
meta_abstention<-cbind(mlogit.odds[2,2], mlogit.conf[2,3:4])
colnames(meta_abstention)<- c("odds","low","high")
meta_abstention$party<-"Abstention"
meta_abstention$country<-"Pooled\n analysis"
meta_abstention$sample<-"Pooled"


#3 Groups: create plot--------------------
comb_vote<-rbind(uk_other, uk_abstention, swiss_other, swiss_abstention, spain_other, spain_abstention, nl17_other, nl17_abstention, nl12_other, nl12_abstention, dk_other, dk_abstention, us_other, us_abstention, germany_other, germany_abstention, venez_other, venez_abstention, meta_other, meta_abstention)

comb_vote$country <-factor(comb_vote$country, levels=c('United Kingdom', 'Germany',  'Denmark', 'Netherlands', 'Switzerland', 'Spain', 'Venezuela', 'United\n States', 'Pooled\n analysis'))
comb_vote$party <-factor(comb_vote$party, levels=c('Populist', 'Abstention'))

comb_vote$sample <-factor(comb_vote$sample, levels=c('UK Election 2015', 'Election 2015', '2016', 'Election 2017', 'Election 2012', '2011', 'ANES 2016', 'GESIS 2017', '2007', 'Pooled'))


fig2_abstain<- ggplot(comb_vote ,aes(x=sample, y=odds))+geom_pointrange(aes(ymin=low,ymax=high), size=1)  + theme_bw()+theme(legend.position="off")+ylab("Odds ratio of voting for a populist party/politician")+xlab("")+geom_hline(yintercept=1,linetype = "dashed", color="red") + coord_flip() + facet_grid(country~party, scales = "free")+ theme(axis.text.x=element_text(size=14), strip.text.y=element_text(size=14)) +  theme(strip.text.y = element_text(angle = 360))

ggsave(fig2_abstain, file="Figures/fig2_populist_abstain.pdf", dpi=900, width = 8, height =6)
